home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CADisptch.cpp
-
- Contains: CADispatcher implementation
-
- Written by: Rick Badertscher
-
- Copyright: © 1993-95 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <0> 8/2/95 RB Created
-
-
- To Do:
- */
-
- #ifndef SOM_ODWindow_xh
- #include "Window.xh"
- #endif
-
- #ifndef _CADISPTCH_
- #include "CADisptch.h"
- #endif
-
- #ifndef _CAFRMUTL_
- #include "CAFrmUtl.h"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _ORDCOLL_
- #include <OrdColl.h>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODFoci_xh
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef _CASESSN_
- #include "CASessn.h"
- #endif
-
- #ifndef _CAUTIL_
- #include "CAUtil.h"
- #endif
-
- #ifndef _CADEBUG_
- #include "CADebug.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
-
- // For window resizing
- #define kMinWindowWidth 192
- #define kMinWindowHeight 64
- #define kMaxWindowWidth 16384
- #define kMaxWindowHeight 16384
-
-
- #pragma segment CALib
-
- //-------------------------------------------------------------------------
-
- static Boolean FilterKeyEvent (EventRecord* event);
- static Boolean IsCADocWindow (ODWindow* window);
-
-
- //-------------------------------------------------------------------------------------
-
- CADispatcher::CADispatcher()
- {
-
- fDispatcher = kODNULL;
- fWindowState = kODNULL;
- fEV = kODNULL;
-
- }
-
- //-------------------------------------------------------------------------------------
-
- CADispatcher::~CADispatcher()
- {
-
- }
-
-
- //-------------------------------------------------------------------------------------
-
- void CADispatcher::Initialize(ODSession* session)
- {
-
- fEV = somGetGlobalEnvironment();
- fDispatcher = session->GetDispatcher(fEV);
- fWindowState = session->GetWindowState(fEV);
-
- }
-
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::DispatchEvent
- //-------------------------------------------------------------------------------------
-
- Boolean CADispatcher::DispatchEvent(ODEventData* event, CAEventInfo* eventInfo)
- {
- Boolean result = kODFalse;
- ODSShort eventType;
-
- eventType = event->what;
-
- switch (eventType)
- {
- case diskEvt:
- case activateEvt:
- case kHighLevelEvent:
- return (kODFalse);
- break;
-
- case mouseDown:
- case mouseUp:
-
- return (this->DispatchMouseEvent (event, eventInfo));
- break;
-
- case updateEvt:
-
- return (this->DispatchUpdateEvent (event));
- //return (false);
- break;
-
- case keyDown:
-
- if (FilterKeyEvent (event)) return (kODFalse);
- break;
-
- case osEvt:
-
- return (this->DispatchOSEvent (event, eventInfo));
- break;
-
- case nullEvent:
- case autoKey:
- case keyUp:
-
- break;
-
- }
-
- // Dispatch the event to OpenDoc
-
- result = fDispatcher->Dispatch( fEV, (ODEventData*) event);
-
- switch (eventType)
- {
- case nullEvent:
- result = false;
- break;
-
- case osEvt:
- result = false;
- break;
-
- }
-
- return result;
-
- }
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::DispatchMenuEvent
- //-------------------------------------------------------------------------------------
-
- Boolean CADispatcher::DispatchMenuEvent(ODEventData* event)
- {
- Boolean result = false;
-
- if (!(result = fDispatcher->Dispatch(fEV,event)))
- result = gCASession->HandleMenuCommand(event->message, event);
-
- return (result);
-
- }
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::DispatchOSEvent
- //-------------------------------------------------------------------------------------
-
- Boolean CADispatcher::DispatchOSEvent( ODEventData* event, CAEventInfo* eventInfo)
- {
- Boolean result = false;
- Boolean isMouseMoved = false;
- Boolean isCAWindow = false;
- WindowPtr window;
-
- isMouseMoved = (((event->message >> 24) & 0x0FF) == mouseMovedMessage);
-
- if (isMouseMoved)
- {
-
- FindWindow(event->where, &window);
-
- if (window)
- {
- TempODWindow tempWindow = fWindowState->AcquireODWindow(fEV, window);
- isCAWindow = IsCADocWindow (tempWindow);
- }
-
- }
-
- result = fDispatcher->Dispatch( fEV, (ODEventData*) event);
-
- result = false;
-
- if (isMouseMoved)
- {
- if (!isCAWindow)
- result = true;
- }
-
- return (result);
-
- }
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::DispatchUpdateEvent
- //-------------------------------------------------------------------------------------
-
- Boolean CADispatcher::DispatchUpdateEvent(ODEventData* event)
- {
-
- Boolean result = false;
- WindowPtr theWindow;
- CADocument* docRef;
-
- theWindow = (WindowPtr)(event->message);
-
- if (theWindow && fWindowState->IsODWindow(fEV, theWindow))
- {
- TempODWindow tempWindow = fWindowState->AcquireODWindow(fEV, theWindow);
- docRef = gCASession->FindCADocumentRefForWindow (tempWindow);
- }
-
- if (!docRef)
- result = fDispatcher->Dispatch( fEV, (ODEventData*) event);
-
- return (result);
-
- }
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::DispatchMouseEvent
- //-------------------------------------------------------------------------------------
-
- Boolean CADispatcher::DispatchMouseEvent(ODEventData* event, CAEventInfo* eventInfo)
- {
-
- CADocument* docRef = NULL;
- Boolean result = kODFalse;
- Boolean isCARootWindow = kODFalse;
- ODWindow* aODWindow = kODNULL;
- ODSShort partCode;
- ODEventInfo odEventInfo;
- EventRecord saveEvent;
- WindowPtr theWindow;
-
- saveEvent = *event;
-
- partCode = FindWindow( event->where, &theWindow );
-
- TRACE (1, "CADispatcher::DispatchMouseEvent - theWindow = %x, partCode = %d", theWindow, partCode);
-
- if (theWindow && (!fWindowState->IsODWindow(fEV, theWindow)))
- {
- DebugStr ("\pmouse down event in non-OD window");
- return (kODFalse);
- }
-
- if (partCode == kODMDInMenuBar)
- return (kODFalse);
-
- // Dispatch the event to OpenDoc
-
- result = fDispatcher->Dispatch( fEV, (ODEventData*) event);
-
- if (!result)
- {
-
- ODFrame* focusFrame = kODNULL;
- ODFrame* frameUnderPoint = kODNULL;;
- ODFacet* facet;
- ODPoint windowPoint;
-
- if (fWindowState->IsODWindow(fEV, theWindow))
- {
- aODWindow = fWindowState->AcquireODWindow(fEV, theWindow);
- docRef = gCASession->FindCADocumentRefForWindow (aODWindow);
- }
-
- if (aODWindow)
- {
-
- aODWindow->GetWindowPoint (fEV, &(event->where), &windowPoint);
- facet = aODWindow->GetFacetUnderPoint (fEV, &windowPoint);
-
- if (facet)
- {
- frameUnderPoint = facet->GetFrame (fEV);
-
- TempODFrame tempFrame = gCASession->GetArbitrator()->AcquireFocusOwner(fEV,
- gCASession->GetODSession()->Tokenize(fEV, kODSelectionFocus));
-
- if (tempFrame && (tempFrame == frameUnderPoint) &&
- (!tempFrame->IsRoot(fEV)))
- {
- //DebugStr ("\p CADispatcher - forcing CADispatchEvent() to return true");
- result = true;
- }
- }
-
- }
-
- ODReleaseObject (fEV, aODWindow);
-
- }
-
-
- if (!result && !docRef)
- {
- // Mouse down is in a non-CA part window
- result = true;
- this->HandleMouseDownInWindow(theWindow, partCode, event);
- }
-
- // Get the stored ODEventInfo info from the proxy part
- // Note: switching on the event record as modified by the OpenDoc dispatcher.
-
- if (result == kODFalse)
- {
-
- switch (event->what)
- {
-
- case kODEvtWindow:
-
- *event = saveEvent; // restore event record
- break;
-
- case kODEvtMouseDownEmbedded:
- case kODEvtBGMouseDownEmbedded:
- case kODEvtMouseDownBorder:
- case kODEvtMouseUpBorder:
- case kODEvtMouseUpEmbedded:
-
-
- if (eventInfo && docRef)
- {
-
- GetEventInfo ((CADocumentRef) docRef, &odEventInfo);
- eventInfo->eventType = event->what;
- eventInfo->embeddedFrame = FrameRefFromFrame ((CADocumentRef) docRef, odEventInfo.embeddedFrame);
- eventInfo->embeddedVisFrame = (CAVisFrame) odEventInfo.embeddedFacet;
- eventInfo->propagated = odEventInfo.propagated;
-
- }
-
- break;
-
- default:
-
- break;
-
-
- }
-
- }
-
- return (result);
-
- }
-
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::HandleMouseDownInWindow
- //-------------------------------------------------------------------------------------
-
- void CADispatcher::HandleMouseDownInWindow(WindowPtr pwindow, ODSShort partCode, ODEventData* event)
- {
- switch (partCode)
- {
-
- case kODMDInGoAway:
- this->HandleMouseDownInCloseBox(pwindow, event);
- break;
-
- case kODMDInDrag:
- this->HandleMouseDownInDragRegion(pwindow, event);
- break;
-
- case kODMDInGrow:
- this->HandleMouseDownInGrowBox(pwindow, event);
- break;
-
- case kODMDInZoomIn:
- case kODMDInZoomOut:
- this->HandleMouseDownInZoomBox(pwindow, partCode,event);
- break;
-
- case kODMDInContent:
- {
- ODWindow* window = fWindowState->AcquireODWindow(fEV,pwindow);
- if (window != kODNULL)
- window->Select(fEV);
- else
- SelectWindow(pwindow);
-
- ODReleaseObject (fEV, window);
- break;
- }
- default:
- break;
- }
- }
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::HandleMouseDownInCloseBox
- //-------------------------------------------------------------------------------------
-
- void CADispatcher::HandleMouseDownInCloseBox(WindowPtr window, ODEventData* event)
- {
-
- TempODWindow tempWindow = fWindowState->AcquireODWindow(fEV, window);
-
- if (TrackGoAway (window, event->where))
- tempWindow->CloseAndRemove(fEV);
- else
- tempWindow->Release(fEV);
-
- }
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::HandleMouseDownInDragRegion
- //-------------------------------------------------------------------------------------
-
- void CADispatcher::HandleMouseDownInDragRegion(WindowPtr platformWindow, ODEventData* event)
- {
-
- TempODWindow tempWindow = fWindowState->AcquireODWindow(fEV, platformWindow);
-
- if (tempWindow)
- tempWindow->Drag(fEV, &event->where, (Rect*)&ODQDGlobals.screenBits.bounds);
- else
- {
- WARN("Dragging non-ODWindow.");
- DragWindow(platformWindow, event->where, &(ODQDGlobals.screenBits.bounds));
- }
-
- }
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::HandleMouseDownInGrowBox
- //-------------------------------------------------------------------------------------
-
- void CADispatcher::HandleMouseDownInGrowBox(WindowPtr pwindow, ODEventData* event)
- {
- ODWindow* window = kODNULL;
- if (fWindowState->IsODWindow(fEV,pwindow))
- window = fWindowState->AcquireODWindow(fEV,pwindow);
-
- if (window == kODNULL)
- return;
-
- if (window->IsResizable(fEV))
- {
- Rect growLimits; // = ODQDGlobals.screenBits.bounds);
-
- ODRgnHandle contRgn =
- ((WindowRecord*)(window->GetPlatformWindow(fEV)))->contRgn;
- Rect currentBounds = (**contRgn).rgnBBox;
-
- window->GetWindowBounds(fEV, ¤tBounds);
-
- growLimits.left = currentBounds.right-currentBounds.left;
- if (growLimits.left > kMinWindowWidth)
- growLimits.left = kMinWindowWidth;
- growLimits.top = currentBounds.bottom-currentBounds.top;
- if (growLimits.top > kMinWindowHeight)
- growLimits.top = kMinWindowHeight;
-
- growLimits.right = kMaxWindowWidth;
- growLimits.bottom = kMaxWindowHeight;
-
- ODSLong newWindowSize = GrowWindow(pwindow, event->where, &growLimits);
- SizeWindow(pwindow, LoWord(newWindowSize), HiWord(newWindowSize), true);
-
- window->AdjustWindowShape(fEV);
-
- Rect r = pwindow->portRect;
- r.left = r.right - 15;
- r.top = r.bottom - 15;
- RgnHandle oldClip = nil;
- GetClip(oldClip = ODNewRgn());
- ClipRect(&r);
- DrawGrowIcon(pwindow);
- SetClip(oldClip);
- DisposeRgn(oldClip);
- }
- ODReleaseObject(fEV, window);
-
- }
-
- //-------------------------------------------------------------------------------------
- // CADispatcher::HandleMouseDownInZoomBox
- //-------------------------------------------------------------------------------------
-
- void CADispatcher::HandleMouseDownInZoomBox(WindowPtr pwindow, ODSShort partcode, ODEventData* event)
- {
- if (TrackBox(pwindow, event->where, partcode))
- {
- ODWindow* window = kODNULL;
-
- if (fWindowState->IsODWindow(fEV,pwindow))
- window = fWindowState->AcquireODWindow(fEV,pwindow);
-
- GrafPtr port;
- GetPort(&port);
- SetPort(pwindow);
-
- ZoomWindow(pwindow, partcode, kODFalse);
-
- SetPort(port);
-
- if (window)
- window->AdjustWindowShape(fEV);
- ODReleaseObject(fEV, window);
- }
- }
-
-
-
-
- //-------------------------------------------------------------------------------------
-
- static Boolean FilterKeyEvent (EventRecord* event)
- {
- Environment* ev = gCASession->GetEV();
- ODArbitrator* arbitrator = gCASession->GetArbitrator();;
- char key;
- Boolean result = false;
-
- key = (char) (event->message & charCodeMask) ;
-
- // if the command key was pressed
- if ((event->modifiers & cmdKey) != 0)
- {
- // Don't dispatch this event, it will be dispatched as a menu
- // event by the CA later.
- result = true;
- }
-
- TempODFrame tempFrame = arbitrator->AcquireFocusOwner (ev,
- gCASession->GetODSession()->Tokenize(ev, kODKeyFocus));
-
- if (tempFrame && tempFrame->IsRoot (ev))
- {
- result = true;
- }
-
- return (result);
-
- }
-
-
- static Boolean IsCADocWindow (ODWindow* window)
- {
-
- if (gCASession->FindCADocumentRefForWindow (window))
- return true;
-
- return false;
-
- }
-
-